package org.hit.burkun.network.tester.branch;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;

import org.hit.burkun.file.FileHelper;
import org.hit.burkun.network.EdgeInfo;
import org.hit.burkun.network.SerializableGraph;
import org.hit.burkun.network.tester.ValidData;
import org.hit.burkun.swalk.lap.SeribaleGraphAdpater;

public class LapcRandomWalkTester {
	
	static double salpha = 0.5;
	public static void main(String[] args) {
//		doTest8noScore();
//		caclc();
//		doTest9Score();
		doTest8Score();
	}
	
	
	
	public static void doTest8Score(){
		//注意改变Adapter的特征提取函数
		salpha = 0.7;
		double[] para = {
				1.222806693429634
				,0.8798642353711366
				,0.5949545016540267
				,-2.542044126049638
				,0.026660902213079034
				,-0.4320819297705938
				,-0.4874321017249358
				,-1.288133211270966
		}; 
	//	doPrWeightOpt(para);
		doPrWeightOptV(para);
	}
	
	
	public static void caclc(){
		System.out.println(ValidData.calcAuc("data/linkpredict/t-weigth-salpha-0.25-sample-1.0-opt.txt"));
//		System.out.println(ValidData.calcAuc("data/linkpredict/t-no-weigth-salpha-0.25-sample-1.0-noweight.txt"));
//		System.out.println(ValidData.calcAuc("data/linkpredict/t-weigth-salpha-0.25-sample-1.0-allone.txt"));
//		System.out.println(ValidData.calcAuc("data/pr2-wight-1.0.txt"));
		System.out.println(ValidData.calcAuc("data/linkpredict/v-weigth-salpha-0.25-sample-1.0-opt.txt"));
//		System.out.println(ValidData.calcAuc("data/linkpredict/v-no-weigth-salpha-0.25-sample-1.0-noweight.txt"));
//		System.out.println(ValidData.calcAuc("data/linkpredict/v-weigth-salpha-0.25-sample-1.0-allone.txt"));
	}
	

	
	private static void writeToFile(String fileName, LinkedList<String> lines){
		FileHelper.writeFile(fileName, lines);
	}

	
	public static void doPrWeightV(int fnum){
//		HashMap<String, HashSet<EdgeInfo>> testTrueTrain = ValidData.readTestTrueTrainObj();
//		HashMap<String, HashSet<EdgeInfo>> testFalseTrain = ValidData.readTestFalseTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testTrueValid = ValidData.readTestTrueValidObj();
		HashMap<String, HashSet<EdgeInfo>> testFalseValid = ValidData.readTestFalseValidObj();
//		HashMap<String, HashSet<EdgeInfo>> testTrue = ValidData.readTestTrueObj();
		SerializableGraph sg  = ValidData.getRemovedSg(false, testTrueValid); //尝试只删除验证集合
		double eps = 1e-4;
		double[] para = new double[fnum];
		for(int i=0; i < fnum; i++){
			para[i] = 1;
		}
		LinkedList<String> res = SeribaleGraphAdpater.getRandomWalkWithRestartTrainValue(para, testTrueValid ,testFalseValid, sg, eps, salpha, true);
		writeToFile("data/linkpredict/v-weigth-salpha-" + salpha + "-sample-1.0-allone" +".txt", res);
		//writeToFile("data/linkpredict/v-weigth-salpha-" + salpha + "-sample-0.5-allone" +".txt", res);
	}
	
	public static void doPrWeightOptV(double[] para){
		HashMap<String, HashSet<EdgeInfo>> testTrueValid = ValidData.readTestTrueValidObj();
		HashMap<String, HashSet<EdgeInfo>> testFalseValid = ValidData.readTestFalseValidObj();
		//更换策略，训练后将边加入到图中
		//SerializableGraph sg  = ValidData.getRemovedSg(false, testTrue);
		SerializableGraph sg  = ValidData.getRemovedSg(false, testTrueValid);
		double eps = 1e-4;
		LinkedList<String> res = SeribaleGraphAdpater.getRandomWalkWithRestartTrainValue(para, testTrueValid,testFalseValid, sg, eps, salpha, true);
		writeToFile("data/linkpredict/v-weigth-salpha-" + salpha + "-sample-1.0-opt" +".txt", res);
		//writeToFile("data/linkpredict/v-weigth-salpha-" + salpha + "-sample-0.5-opt" +".txt", res);
	}
	
	
	
	
	public static void doPrWeight(int fnum){
		HashMap<String, HashSet<EdgeInfo>> testTrueTrain = ValidData.readTestTrueTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testFalseTrain = ValidData.readTestFalseTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testTrue = ValidData.readTestTrueObj();
		SerializableGraph sg  = ValidData.getRemovedSg(false, testTrue);
		double eps = 1e-4;
		
		double[] para = new double[fnum];
		for(int i=0; i < fnum; i++){
			para[i] = 1;
		}
		LinkedList<String> res = SeribaleGraphAdpater.getRandomWalkWithRestartTrainValue(para, testTrueTrain,testFalseTrain, sg, eps, salpha, true);
		writeToFile("data/linkpredict/t-weigth-salpha-" + salpha + "-sample-1.0-allone" +".txt", res);
		//writeToFile("data/linkpredict/t-weigth-salpha-" + salpha + "-sample-0.5-allone" +".txt", res);
	}
	
	public static void doPrWeightOpt(double[] para){
		HashMap<String, HashSet<EdgeInfo>> testTrueTrain = ValidData.readTestTrueTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testFalseTrain = ValidData.readTestFalseTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testTrue = ValidData.readTestTrueObj();
		//更换策略，训练后将边加入到图中
		SerializableGraph sg  = ValidData.getRemovedSg(false, testTrue);
		double eps = 1e-4;
		LinkedList<String> res = SeribaleGraphAdpater.getRandomWalkWithRestartTrainValue(para, testTrueTrain,testFalseTrain, sg, eps, salpha, true);
		writeToFile("data/linkpredict/t-weigth-salpha-" + salpha + "-sample-1.0-opt" +".txt", res);
		//writeToFile("data/linkpredict/t-weigth-salpha-" + salpha + "-sample-0.5-opt" +".txt", res);
	}
	
}
